package xin.nick.demo.config;

import org.dom4j.DocumentException;
import xin.nick.persistence.core.builder.SqlSessionFactoryBuilderByProperties;
import xin.nick.persistence.core.session.SqlSessionFactory;
import xin.nick.summer.annotation.Bean;
import xin.nick.summer.annotation.Configuration;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.util.Properties;

/**
 * @author Nick
 * @date 2021/5/24
 * @description // 通过配置类的方式,将 Persistence 框框 集成到 Summer 框框
 */
@Configuration
public class PersistenceConfig {

    /**
     * 获取 SqlSessionFactory
     * @param properties
     * @return
     */
    @Bean
    public SqlSessionFactory getSqlSessionFactory(Properties properties) {

        try {
            return SqlSessionFactoryBuilderByProperties.build(properties);
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
